Categories: Tips & Tricks

Display the_excerpt only if there is text

In my new theme, I am using this coded trick to display the excerpt on a single post only if I’ve got text inside. Usually if you use the_excerpt and you don’t have one, it will fake one for you.

This is not something that I wanted to do on the single post page. So I used the following code to check if the excerpt existed.

if ( !empty( $post->post_excerpt ) ) :

Once this action is taken into account, you can factor in what code you want to out put if the post_excerpt isn’t empty.

if ( !empty( $post->post_excerpt ) ) :
 the_excerpt();
else :
 false;
endif;

The above code checks if there is an excerpt and print’s it to the screen. If there isn’t an except, it doesn’t do anything.

Web Master

Hi, I am Miguel, I bought this site in 2009. So I now run or manage the site. Please visit my new website or follow me on twitter @W3i.

Recent Posts

The first WordPress 2.7 maintenance release

Well, it has taken along time, but it's official. WordPress.org has released a maintenance release…

2 hours ago

How to Increase Awareness and Generate Leads with Local SEO

The rise of Local SEO has made it easier for businesses to increase brand awareness…

14 hours ago

Jon Asked: How to add thumbnails above post on the THiCK theme

I was asked by a reader: I'm using the THiCK theme for my new design…

1 day ago

13 Best WordPress Email Marketing Plugins

The article lists the 13 best WordPress email marketing plugins for 2022 - HubSpot, ConvertKit,…

2 days ago

AI Chips in 2024: Navigating NVIDIA’s Dominance and Emerging Competitors

In 2024, NVIDIA remains a dominant force in the AI chip market with its innovative…

2 days ago

21 Best ChatGPT Prompts for Marketing and How to Utilize Them Effectively

In the rapidly evolving realm of digital marketing, ChatGPT has emerged as an invaluable tool,…

3 days ago